package net.xiaosaguo.mymall.cart.pojo.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * description: 购物车对象
 *
 * @author xiaosaguo
 * @date 2020/07/08
 */
@Data
public class Cart {

    List<CartItem> items;

    private Integer countNum;// 商品数量
    private Integer countType;// 商品类型
    private BigDecimal totalAmount;// 商品总价
    private BigDecimal reduce = new BigDecimal("0.00");// 减免价格

    public Integer getCountNum() {
        int count = 0;
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        if (items != null && !items.isEmpty()) {
            return items.size();
        }
        return 0;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                amount = amount.add(item.getTotalPrice());
            }
        }
        amount = amount.subtract(getReduce());
        return amount;
    }

}
